/* 
 * File:   networkcommunication.h
 * Author: iezahel
 *
 * Created on January 1, 2009, 10:32 PM
 */

#ifndef _NETWORKCOMMUNICATION_H
#define	_NETWORKCOMMUNICATION_H

#include "pong.h"
#include "game_protocol.h"

#include "assert.h"

class NetworkCommunication {
private:
    TCPsocket tcp_sock; /* The communication socket */

    int Add32BitData(int val, char* buf, int pos) {
        SDLNet_Write32(val, buf + pos);
        return pos + 4;
    }

    int Add16BitData(short val, char* buf, int pos) {
        SDLNet_Write16(val, buf + pos);
        return pos + 2;
    }

    int Add8BitData(char val, char* buf, int pos) {
        buf[pos] = val;
        return pos + 1;
    }

    GAME_ERROR_CODES SendGeneralCommand(struct GameCommand* cmd);
public:
    NetworkCommunication(TCPsocket tcp_sock);
    NetworkCommunication(const NetworkCommunication& orig);
    virtual ~NetworkCommunication();

     /* Those are all blocking socket commands */
    GAME_ERROR_CODES SendResumeCommand();
    GAME_ERROR_CODES SendPauseCommand();

    GAME_ERROR_CODES SendPlayerStateCommand(int velocity, int pos_y = -1);
    GAME_ERROR_CODES SendBallStateCommand(int velocity_x, int velocity_y, int pos_x = -1, int pos_y = -1);

    GAME_ERROR_CODES SendInitialConfig(int position, int width, int height,
                                       int ball_speed, int player_speed);

    GAME_ERROR_CODES SendMissedBallCommand();
};

#endif	/* _NETWORKCOMMUNICATION_H */

